<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <search ref='search' :config='searchConfig' @getHeight='getHeight' @search='search' />
    <!-- table区域-begin -->
    <div class='page_table'>
      <vxe-grid
        ref='xGrid'
        v-bind='vexConfig'
        :align='left'
        :border='true'
        :columns='columns'
        :data='dataSource'
        :height='pageHeight-seachHeight-90'
        :loading='loading'
        :resizable='true'
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        :showOverflow='true'
        :toolbar-config='tableToolbar'
        size='mini'
        @radio-change='radioChangeEvent'
        :radio-config="{ trigger: 'row'}"
      >
        <template #toolbar_buttons>
          <div class='table-operator'>
            <a-button v-has="'AssetApprovalList:approval'" :disabled="selectionRows.length!=1||[3,4].includes(selectionRows[0].approvalStatus)" @click="handleEdit1(selectionRows[0])">审核</a-button>
            <a-button type="primary" @click="downExportXls('sfaVisitAssets_service')">导出</a-button>
          </div>
        </template>
        <template #detail="{ row,rowIndex }">
          <a @click="handleDetail(row)">{{ row.customerCode }}</a>
        </template>
        <template #status='{ row }'>
          <a-switch :checked='row.status' size='small' @change='handleStatus(row,$event)' />
        </template>
        <template #action='{ row:record }'>
          <a href='javascript:' @click='handleBusiness("资产审批",record)'>日志</a>
<!--    <a @click='handleEdit1(record)'>变更</a>-->
          <!--          <span v-if='record.fileUrl'>-->
          <!--            <a-divider type='vertical' />-->
          <!--            <a :href='record.fileUrl'>删除</a>-->
          <!--          </span>-->
        </template>
        <template #pager>
          <vxe-pager
            :currentPage.sync='ipagination.current'
            :layouts="['Total', 'PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump','Sizes', 'FullJump']"
            :page-size.sync='ipagination.pageSize'
            :pageSizes='ipagination.pageSizeOptions'
            :total='ipagination.total'
            @page-change='handlePageChange'>
          </vxe-pager>
        </template>
      </vxe-grid>
    </div>
    <!-- table区域-end -->
    <!-- 表单区域 -->
    <asset-approval-list-modal ref='modalForm'  @ok="modalFormOk"></asset-approval-list-modal>
    <asset-change-modal ref='modalForm2'  @ok="modalFormOk"></asset-change-modal>
    <asset-commit-modal ref='modalForm3'  @ok="modalFormOk"></asset-commit-modal>
    <business-log ref="businessLog"></business-log>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { PageListMixin } from '@/mixins/PageListMixin'
import { postAction,getAction } from '@/api/manage'
import assetApprovalListModal from './modules/AssetApprovalListModal'
import AssetChangeModal from './modules/AssetChangeModal'
import Vue from 'vue'
import { ACCESS_TOKEN } from '@/store/mutation-types'
import AssetCommitModal from '@views/mdm/terminal/modules/AssetCommitModal'
export default {
  name: 'SfaVisitLineList',
  mixins: [PageListMixin],
  components: {
    assetApprovalListModal,
    AssetChangeModal,
    AssetCommitModal
  },
  data() {
    return {
      tokenHeader1: {'Authorization':  'Bearer ' + Vue.ls.get(ACCESS_TOKEN).access_token},
      description: '订单中心',
      //查询区域
      searchConfig:[
        {
          type: 'input',
          name: 'customerCode',
          placeholder: '门店编码'
        },
        {
          type: 'input',
          name: 'customerName',
          placeholder: '门店名称'
        },
        {
          type: 'j-select',
          dictCode:'is_allocation',
          name: 'isAllocation',
          placeholder: '类型'
        },
        {
          type: 'j-select',
          dictCode:'bpm_status',
          name: 'approvalStatus',
          placeholder: '审批状态'
        },
        {
          type: 'input',
          name: 'processNo',
          placeholder: '流程编号'
        },
        {
          type: 'j-select',
          dictCode:'approval_assets',
          name: 'currentNode',
          placeholder: '审批流程'
        },
        {
          type: 'input',
          name: 'createName',
          placeholder: '创建人'
        },
        {
          type: 'date-range', //范围选择
          range: ['startDate', 'endDate'],
          name: 'range',
          format: 'YYYY-MM-DD',
          placeholder: ['开始时间', '结束时间']
        }
      ],
      // 表头
      columns: [
        { type: 'radio', width: 50, fixed: 'left' },
        {
          title: '流程编号',
          minWidth:80,
          field: 'processNo',
        },
        {
          title: '门店编号',
          minWidth:80,
          field: 'customerCode',
          slots: { default: 'detail'}
        },
        {
          title: '门店名称',
          minWidth:80,
          field: 'customerName',
        },
        {
          title: '类型',
          minWidth:80,
          field: 'isAllocationStr'
        },
        {
          title: '是否有资产',
          minWidth:80,
          field: 'isAssetsStr'
        },
        {
          title: '是否A类陈列位置',
          minWidth:120,
          field: 'isClassADisplayStr'
        },
        {
          title: '备注',
          minWidth:80,
          field: 'remarks'
        },
        {
          title: '创建人',
          minWidth:80,
          field: 'createName'
        },
        {
          title: '创建时间',
          minWidth:80,
          field: 'createTime'
        },
        {
          title: '审批流程',
          align: 'left',
          field: 'currentNodeDesc',
          fixed: 'right',
          minWidth: 120
        },
        {
          title: '审批状态',
          align: 'left',
          field: 'approvalStatusStr',
          width: 80,
          fixed: 'right',
          minWidth: 80
        },
        // {
        //   title: '操作',
        //   field: 'action',
        //   fixed: 'right',
        //   width:120,
        //   slots: {
        //     default: 'action'
        //   }
        // }
      ],
      isorter: {
        permflag: 'asset_approval_page_impl'
      },
      url: {
        list: window._CONFIG['domianSfaURL'] + '/sfaVisitAssetsController/findPageToExamineList',
        // delete: window._CONFIG['domianSfaURL'] + '/visit/sfaVisitLineController/delete',
        detail: window._CONFIG['domianSfaURL'] + '/sfaVisitAssetsController/getToExamineInfo',
        // deleteBatch: window._CONFIG['domianSfaURL'] + '/visit/sfaVisitLineController/deleteBatch',
        // exportXlsUrl: window._CONFIG['domianSfaURL'] + '/sfaOrderController/exportXls',
        // importExcelUrl: window._CONFIG['domianSfaURL'] + '/sfaOrderController/importExcel'
      }
    }
  },
  computed: {
    importExcelUrl: function() {
      return `${this.url.importExcelUrl}`
    }
  },

  methods: {
    // 地图初始化函数，本例取名为init，开发者可根据实际情况定义

    //  审批
    handleEdit: async function(record) {
      if (this.url.detail) {
        const res = await getAction(this.url.detail, { id: record.id })
        if (res.success) {
          if (res.result) {
            record = res.result
            console.log(record)
          }
        } else {
          this.$message.error(res.message)
        }
      }
      this.$refs.modalForm.title = '详情'
      this.$refs.modalForm.disableSubmit = true
      this.$refs.modalForm.edit(record)
    },
    handleDetail: async function (record, url, params, method = getAction, modalForm) {
      if (url || this.url.detail) {
        const res = await method(url || this.url.detail, params || { id: record.id })
        if (res && res.result) {
          record = res.result
        }
      }
      let modal = this.$refs.modalForm2
      if(record.isAllocation==1){
        modal = this.$refs.modalForm3
      }
      modal.edit(record)
      modal.title = '详情'
      modal.disableSubmit = true
    },
    //  编辑
    handleEdit1: async function(record) {
      if (this.url.detail) {
        const res = await getAction(this.url.detail, { id: record.id })
        if (res.success) {
          if (res.result) {
            record = res.result
            console.log(record)
          }
        } else {
          this.$message.error(res.message)
        }
      }
      let modalForm = this.$refs.modalForm2
      if(record.isAllocation==1){
        modalForm = this.$refs.modalForm3
      }
      modalForm.title = '审批'
      modalForm.disableSubmit = true
      this.selectionRows = []
      modalForm.edit(record)
    },

  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>